const { mappedPortTable, mappingPorts } = require('./cache')
const util = require('util')

async function forward(conn, data) {
    const child = await conn.forward(data.clientPort, data.serverPort, data.isIn, data.serverSock)
    data.host = conn.options.host
    data.notConnected = false
    await mappedPortTable.save(data)
    const key = util.format('%s-%s', data.host, data.clientPort)
    mappingPorts.set(key, {
        data,
        child
    })
}

module.exports = {
    forward
}
